package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.SSD2MoldRecordPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.SSD2MoldRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app-api/ssd2moldrecord")
@CrossOrigin
@SaIgnore
@Slf4j
public class APPSSD2MoldRecordController {
	private SSD2MoldRecordService ssd2MoldRecordService;
	@Autowired
	public void setSsd2MoldRecordService(SSD2MoldRecordService ssd2MoldRecordService) {
		this.ssd2MoldRecordService = ssd2MoldRecordService;
	}

	@PostMapping("/addJxRecord")
	public SaResult addJxRecord(@RequestBody SSD2MoldRecordPO ssd2MoldRecordPO){
		ssd2MoldRecordService.addJxRecord(ssd2MoldRecordPO);
		return SaResult.ok();
	}

	@GetMapping("/getJxRecordTimeLine")
	public SaResult getJxRecordTimeLine(String machineNo, String beginDate, String endDate) {
		return SaResult.data(ssd2MoldRecordService.getJxRecordTimeLine(machineNo,beginDate,endDate));
	}

	@GetMapping("/getJxRecordByID")
	public SaResult getJxRecordByID(int recordID){
		SSD2MoldRecordPO ssd2MoldRecordPO = ssd2MoldRecordService.getJxRecordByID(recordID);
		if(ObjectUtil.isEmpty(ssd2MoldRecordPO)) return SaResult.error("获取数据异常");
		return SaResult.data(ssd2MoldRecordPO);
	}

	@PostMapping("/uptJxRecord")
	public SaResult uptJxRecord(@RequestBody SSD2MoldRecordPO ssd2MoldRecordPO){
		ssd2MoldRecordService.uptJxRecord(ssd2MoldRecordPO);
		return SaResult.ok();
	}

	@PostMapping("/delJxRecord")
	public SaResult delJxRecord(@RequestBody SSD2MoldRecordPO ssd2MoldRecordPO){
		ssd2MoldRecordService.delJxRecord(ssd2MoldRecordPO.getRecordID());
		return SaResult.ok();
	}
}
